﻿<%@ Page Title="" Language="vb" AutoEventWireup="false" MasterPageFile="~/Master_Page/Master_IPORT.Master" CodeBehind="Stock_Management.aspx.vb" Inherits="I_PORT.Stock_Management" %>

<%@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="asp" %>
<%@ Register Src="~/Control/Confirm.ascx" TagName="Confirm1" TagPrefix="Confirm" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" runat="server">
<script type="text/javascript" language="javascript">
    var _source;
    // keep track of the popup div
    var _popup;

    function showConfirm(customerid) {
        this._source = customerid;
        this._popup = $find('ModalPopupExtender3');
        this._popup.show();
    }
    function okClick() {
        //  find the confirm ModalPopup and hide it
        this._popup.hide();

        __doPostBack(this._source.name, '');

    }

    function cancelClick() {
        //  find the confirm ModalPopup and hide it
        this._popup.hide();
    }
    function closeModal() {
        document.getElementById('ctl00_contentplaceholder1_TabStock_TabNewStock_framePopup').src = '../MasterPopup/Stock_Popup.aspx';
        var mpu = $find('ctl00_ContentPlaceHolder1_TabStock_TabNewStock_ModalPopupExtender1');
        mpu.hide();
        document.getElementById('ctl00_contentplaceholder1_TabStock_TabNewStock_btnLoad').click();
    }
    function showPopup() {
        document.getElementById('ctl00_contentplaceholder1_TabStock_TabNewStock_framePopup').contentWindow.location.reload(true);
    }
    function checkNumber(e) {
        var keycode;

        if (window.event) keycode = window.event.keyCode; // ใช้ IE อ่ะ

        else if (e) keycode = e.which; // ใช้ Firefox เน่าะ

        if (((keycode > 47) && (keycode < 58)) || (keycode == 190) || (keycode == 46)) {
            return true;
        }
        return false;
    }
</script>
    <asp:UpdatePanel ID="UpdatePanel1" runat="server">
    <ContentTemplate>
       <table width="100%" border="0" cellpadding="0" cellspacing="0">
          <tr>
             <td align="left">
                  <asp:TabContainer ID="TabStock" runat="server" Width="100%" AutoPostBack="true"
                            ActiveTabIndex="0">
                            <asp:TabPanel ID="TabNewStock" runat="server" HeaderText="Edit/New Stock">
                                <ContentTemplate>
                                   <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                       <tr>
                                         <td>
                                                           <table width="100%" border="0" cellpadding="2" cellspacing="0">
        <tr>
             <td style="width:20%;" align="right"><asp:Label ID="lbNameCustomer" runat="server" SkinID="lbtxt" Text="Grade :"></asp:Label>&nbsp;</td>
             <td align="left"><asp:TextBox ID="txtGrade" runat="server"></asp:TextBox>
             </td>
        </tr>
        <tr>
             <td style="width:20%;" align="right"><asp:Label ID="Label1" runat="server" SkinID="lbtxt" Text="Brand :"></asp:Label>&nbsp;</td>
             <td align="left"><asp:TextBox ID="txtBrand" runat="server"></asp:TextBox>
             <asp:Button ID="btnSearch" runat="server" Text="ค้นหา" CssClass="ButtonStyle" />
             </td>
        </tr>
        <tr>
           <td style="height:5px;"><img src="../Image/space.gif" /></td>
        </tr>
        <tr>
           <td align="center" colspan="2">
              <asp:GridView ID="gridStock" runat="server" SkinID="gridblue"  DataKeyNames="Stock_Code,Grade,Brand,Amount"
                     AutoGenerateColumns="False">
                     <PagerTemplate>
                                            <table>
                                                <tr>
                                                    <td>
                                                        <asp:ImageButton ID="ImgFirst" runat="server" Height="22px" ImageUrl="../Image/arrow-first.gif"
                                                            OnCommand="Paginate" CommandArgument="First" CommandName="Page" />
                                                    </td>
                                                    <td>
                                                        <asp:ImageButton ID="ImgBack" runat="server" Height="22px" ImageUrl="../Image/arrow-back.gif"
                                                            OnCommand="Paginate" CommandArgument="Prev" CommandName="Page" />
                                                    </td>
                                                    <td valign="top">
                                                        Page
                                                        <asp:DropDownList ID="ddlPage" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlPage_SelectedIndexChanged">
                                                        </asp:DropDownList>
                                                        of
                                                        <asp:Label ID="lbPageCount" runat="server" Text="Label"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:ImageButton ID="ImgNext" runat="server" Height="22px" ImageUrl="../Image/arrow-next.gif"
                                                            OnCommand="Paginate" CommandArgument="Next" CommandName="Page" />
                                                    </td>
                                                    <td>
                                                        <asp:ImageButton ID="ImgEnd" runat="server" Height="22px" ImageUrl="../Image/arrow-end.gif"
                                                            OnCommand="Paginate" CommandArgument="Last" CommandName="Page" />
                                                    </td>
                                                </tr>
                                            </table>
                                        </PagerTemplate>
                     <Columns> 
                         <asp:BoundField HeaderText="GRADE" DataField="Grade" />
                         <asp:BoundField HeaderText="BRAND" DataField="Brand" />
                         <asp:BoundField HeaderText="AMOUNT" DataField="Amount" />
                         <asp:TemplateField HeaderText="แก้ไข">
                             <ItemTemplate>
                                 <asp:ImageButton ID="imgedit" CommandName="cmdedit" CommandArgument="<%# Container.DataItemIndex %>"  runat="server" ImageUrl="~/Image/edit-24.gif" />
                             </ItemTemplate>
                             <ItemStyle Width="50px" />
                         </asp:TemplateField>
                        <asp:TemplateField HeaderText="ลบ">
                            <ItemTemplate>
                                 <asp:ImageButton ID="imgdelete" CommandName="cmddelete" CommandArgument="<%# Container.DataItemIndex %>" OnClientClick="showConfirm(this); return false;"  runat="server" ImageUrl="~/Image/cancel-24.gif" />
                             </ItemTemplate>
                            <ItemStyle Width="50px" />
                         </asp:TemplateField>
                     </Columns>
                 </asp:GridView>
           </td>
        </tr>
        <tr>
           <td style="height:5px;"><img src="../Image/space.gif" /></td>
        </tr>
        <tr>
           <td style="width:20%;" align="right"></td>
           <td align="left"><asp:Button ID="btnNewStock" runat="server" Text="New Item"  OnClientClick="showPopup();" CssClass="ButtonStyle" /></td>
        </tr>
     </table>
                                         </td>
                                       </tr>
                                   </table>
                                    <asp:Button ID="btnAdd" runat="server" style="display:none" />
      <asp:Button ID="btnLoad" runat="server" Text="ปิด" style="display:none;" />
     <asp:Button ID="BtnTrigger" runat="server" style="display:none;" />
    <asp:ModalPopupExtender ID="ModalPopupExtender1" runat="server" BackgroundCssClass="Background"
     TargetControlID="btnAdd" PopupControlID="PopupAdd" DynamicServicePath="" Enabled="True" >
    </asp:ModalPopupExtender>
            <asp:ModalPopupExtender ID="ModalPopupExtender3" BehaviorID="ModalPopupExtender3" runat="server" 
                                    OkControlID="ctl00_contentplaceholder1_TabStock_TabNewStock_ConfirmDelete_btnOk" 
                                    OnOkScript="okClick();" 
                                    CancelControlID="ctl00_contentplaceholder1_TabStock_TabNewStock_ConfirmDelete_btnNo"     
                                    OnCancelScript="cancelClick();" 
                                     BackgroundCssClass="Background" 
                                      PopupControlID="PanelConfirm" TargetControlID="BtnTrigger" 
                                        DynamicServicePath="" Enabled="True" >
        </asp:ModalPopupExtender>
    <asp:Panel ID="PopupAdd" runat="server" Style="display: none;">
        <table>
            <tr>
                <td>
                    <iframe runat="server" id="framePopup" class="Style-Iframe" marginheight="0px" marginwidth="0px" src="../MasterPopup/Stock_Popup.aspx" >
                    </iframe>
                </td>
            </tr>
        </table>
    </asp:Panel>
        <asp:Panel ID="PanelConfirm" runat="server" style="display:none;">
       <Confirm:Confirm1 ID="ConfirmDelete" runat="server" ></Confirm:Confirm1>
    </asp:Panel>
                                </ContentTemplate>
                              </asp:TabPanel>
                              <asp:TabPanel ID="TabAddStock" runat="server" HeaderText="Add/Remove Stock">
                                <ContentTemplate>
                                   <table width="100%" border="0" cellpadding="0" cellspacing="0">
                                       <tr>
                                         <td>
                                                           <table width="100%" border="0" cellpadding="2" cellspacing="0">
        <tr>
             <td style="width:20%;" align="right"><asp:Label ID="Label2" runat="server" SkinID="lbtxt" Text="Grade :"></asp:Label>&nbsp;</td>
             <td align="left"><asp:TextBox ID="txtGrade2" runat="server"></asp:TextBox>
             </td>
        </tr>
        <tr>
             <td style="width:20%;" align="right"><asp:Label ID="Label3" runat="server" SkinID="lbtxt" Text="Brand :"></asp:Label>&nbsp;</td>
             <td align="left"><asp:TextBox ID="txtBrand2" runat="server"></asp:TextBox>
             <asp:Button ID="btnSearch2" runat="server" Text="ค้นหา" CssClass="ButtonStyle" />
             </td>
        </tr>
        <tr>
           <td style="height:5px;"><img src="../Image/space.gif" /></td>
        </tr>
        <tr>
           <td align="center" colspan="2">
              <asp:GridView ID="gridStockAdd" runat="server" SkinID="gridblue"  DataKeyNames="Stock_Code,Grade,Brand,Amount,Active,Type_Additional,Color"
                     AutoGenerateColumns="False">
                     <PagerTemplate>
                                            <table>
                                                <tr>
                                                    <td>
                                                        <asp:ImageButton ID="ImgFirst" runat="server" Height="22px" ImageUrl="../Image/arrow-first.gif"
                                                            OnCommand="Paginate2" CommandArgument="First" CommandName="Page" />
                                                    </td>
                                                    <td>
                                                        <asp:ImageButton ID="ImgBack" runat="server" Height="22px" ImageUrl="../Image/arrow-back.gif"
                                                            OnCommand="Paginate2" CommandArgument="Prev" CommandName="Page" />
                                                    </td>
                                                    <td valign="top">
                                                        Page
                                                        <asp:DropDownList ID="ddlPage" runat="server" AutoPostBack="true" OnSelectedIndexChanged="ddlPage2_SelectedIndexChanged">
                                                        </asp:DropDownList>
                                                        of
                                                        <asp:Label ID="lbPageCount" runat="server" Text="Label"></asp:Label>
                                                    </td>
                                                    <td>
                                                        <asp:ImageButton ID="ImgNext" runat="server" Height="22px" ImageUrl="../Image/arrow-next.gif"
                                                            OnCommand="Paginate2" CommandArgument="Next" CommandName="Page" />
                                                    </td>
                                                    <td>
                                                        <asp:ImageButton ID="ImgEnd" runat="server" Height="22px" ImageUrl="../Image/arrow-end.gif"
                                                            OnCommand="Paginate2" CommandArgument="Last" CommandName="Page" />
                                                    </td>
                                                </tr>
                                            </table>
                                        </PagerTemplate>
                     <Columns> 
                         <asp:BoundField HeaderText="GRADE" DataField="Grade" />
                         <asp:BoundField HeaderText="BRAND" DataField="Brand" />
                         <asp:BoundField HeaderText="AMOUNT" DataField="Amount" />
                         <asp:BoundField HeaderText="Status" />
                          <asp:TemplateField HeaderText="Active">
                             <ItemTemplate>
                                 <asp:Button ID="btnActive" runat="server" CssClass="ButtonStyle" Text="Active"  CommandName="cmdActive" CommandArgument="<%# Container.DataItemIndex %>"  />
                             </ItemTemplate>
                             <ItemStyle Width="105px" HorizontalAlign="Center" />
                         </asp:TemplateField>
                         <asp:TemplateField HeaderText="">
                             <ItemTemplate>
                                 <asp:Button ID="btnAddRemove" runat="server" CssClass="ButtonStyle" Text="Add/Remove Stock"  CommandName="cmdedit" CommandArgument="<%# Container.DataItemIndex %>"  Width="135px" />
                             </ItemTemplate>
                             <ItemStyle Width="140px" HorizontalAlign="Center" />
                         </asp:TemplateField>
                     </Columns>
                 </asp:GridView>
           </td>
        </tr>
        </table>
        <table width="100%" border="0" cellpadding="2" cellspacing="0">
        <tr>
           <td style="height:5px;"><img src="../Image/space.gif" /></td>
        </tr>
        <tr>
          <td>
            <asp:Panel ID="panelAddRemove" runat="server" Visible="false">
                 <fieldset style="width:95%;"><legend style="color: #848585; font-family: Tahoma; font-size: 14px; font-weight: bold;">
                                               Add/Remove</legend>
                      <table width="100%" border="0" cellpadding="2" cellspacing="0">
                        <tr>
                          <td align="right" style="width:220px;" ><asp:Label ID="lbold" runat="server" SkinID="lbtxt" Text="Action :" ></asp:Label>&nbsp;</td>
                           <td align="left">
                               <asp:DropDownList ID="ddlAction" runat="server" SkinID="ddl">
                                  <asp:ListItem Value="A">Add</asp:ListItem>
                                  <asp:ListItem Value="R">Remove</asp:ListItem>
                               </asp:DropDownList>
                           </td>
                        </tr>
                        <tr>
                          <td align="right" style="width:220px;" ><asp:Label ID="Label4" runat="server" SkinID="lbtxt" Text="Amount :" ></asp:Label>&nbsp;</td>
                           <td align="left">
                              <asp:TextBox ID="txtAmount" runat="server" onkeypress="return checkNumber(this);" Width="60px" ></asp:TextBox>
                           </td>
                        </tr>
                        <tr>
                          <td align="right" style="width:220px;" valign="top" ><asp:Label ID="Label5" runat="server" SkinID="lbtxt" Text="หมายเหตุ :" ></asp:Label>&nbsp;</td>
                           <td align="left" valign="top">
                              <asp:TextBox ID="txtRemark" runat="server" MaxLength="500" TextMode="MultiLine" Height="60px" Width="90%" ></asp:TextBox>
                           </td>
                        </tr>
                        <tr>
                          <td align="right" style="width:220px;" >&nbsp;</td>
                           <td align="left">
                              <asp:Button ID="btnConfirm" runat="server" CssClass="ButtonStyle" Text="Confirm" />
                              <asp:Button ID="btnBack" runat="server" CssClass="ButtonStyle" Text="Close" />
                           </td>
                        </tr>
                      </table>
                                               
                </fieldset></asp:Panel>
          </td>
        </tr>
     </table>
     
                                         </td>
                                       </tr>
                                   </table>
                                </ContentTemplate>
                              </asp:TabPanel>
                 </asp:TabContainer>
             </td>
          </tr>
       </table>
       
    </ContentTemplate>
   </asp:UpdatePanel>
</asp:Content>
